package com.zjbti.listview;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    String[] names={"小红","小白","小黑"};

    ListView listView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView=findViewById(R.id.id_list);
        MyBaseAdapter baseAdapter=new  MyBaseAdapter();
        listView.setAdapter(baseAdapter);


    }

    class  MyBaseAdapter extends BaseAdapter{
        public int getCount(){
            return  names.length;
        }

        @Override
        public Object getItem(int i) {
            return names[i];
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
             view= LayoutInflater.from(getApplicationContext()).inflate(R.layout.list_item2,null);
            TextView textView=view.findViewById(R.id.id_list2);
            textView.setText(names[i]);
            return view;
        }
    }
}